package com.baizhi.service;

import com.baizhi.dao.ProductOrderMapper;
import com.baizhi.entity.ProductOrder;
import com.baizhi.entity.ProductOrderExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.UUID;

@Service("productOrderService")
@Transactional
public class ProductOrderServiceImpl implements ProductOrderService{

    @Resource
    private ProductOrderMapper productOrderMapper;

    @Autowired
    private HttpServletRequest request;

    @Override
    public ProductOrder findById(String id) {
        return productOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ProductOrder> findAll() {
        ProductOrderExample productOrderExample = new ProductOrderExample();
        return productOrderMapper.selectByExample(productOrderExample);
    }

    @Override
    public List<ProductOrder> findByOrderId(String orderId) {
        ProductOrderExample productOrderExample = new ProductOrderExample();
        productOrderExample.createCriteria().andOrderidEqualTo(orderId);
        return productOrderMapper.selectByExample(productOrderExample);
    }

    @Override
    public void save(ProductOrder productOrder) {
        productOrder.setId(UUID.randomUUID().toString());
        productOrderMapper.insert(productOrder);
    }
}
